/**
 * Created by Administrator on 2018/11/23.
 */
window.onload=function(){
    var account =  document.getElementById("account");
    var Phone =  document.getElementById("phone");
    var accountContext =  document.getElementById("accountContext");
    var PhoneContext =  document.getElementById("phoneContext");
    //显示账号注册
    account.onclick = function(){
        PhoneContext.style.display="none";
        accountContext.style.display="block";
    }
    //显示手机号注册
    Phone.onclick = function(){
        PhoneContext.style.display="block";
        accountContext.style.display="none";
    }
    //表单的提交验证。
    var btn01 = document.getElementById("btn01");
    btn01.onclick=function(){
        //验证表单中的数据的合法性。
        //获得输入的用户名
        var account = form1.accountRig.value;
        var pwd = form1.pwdRig.value;
        var pwd2 = form1.pwdRig2.value;
        if(account==""){
            alert("请输入账号");
            form1.account.focus();
            return ;
        }
        if(pwd==""){
            alert("请输入密码");
            form1.pwd.focus();
            return ;
        }
        if(pwd!=pwd2){
            alert("密码重复输入错误");
            form1.pwd2.focus();
            return ;
        }
        //把密码进行加密
        form1.pwdRig.value =  hex_md5(pwd);
        //提交表单
        form1.submit();
    }
    var btn02=document.getElementById("btn02");
    btn02.onclick=function () {
        //  把页面输入的手机号发生给服务器
        //1.获得页面输入的手机号码
        var phone=form2.phoneRig.value;
        if (!/^1[3|4|5|7|8][0-9]{9}$/.test(phone)){
            alert("手机号码不正规");
            return;
        }

        var url="/Bookstore/send?phone=" + phone;

        var req=new XMLHttpRequest();

        req.open("POST",url);
        req.send(null);
        req.onreadystatechange=function () {
            if(req.readyState==4){
                if(req.status==200||req.status==304){
                    alert(req.response);
                }
            }
        }

    }
    var btn03 = document.getElementById("btn03");
    btn03.onclick=function(){
        //验证表单中的数据的合法性。
        //获得输入的用户名
        var phoneRig = form2.phoneRig.value;
        var codeRig = form2.codeRig.value;
        if(codeRig==""){
            alert("请输入验证码");
            form2.codeRig.focus();
            return ;
        }
        form2.submit();
    }

        var url="/Bookstore/send?phoneRig=" + phoneRig;

        var req=new XMLHttpRequest();

        req.open("POST",url);
        req.send(null);
        req.onreadystatechange=function () {
            if(req.readyState==4){
                if(req.status==200||req.status==304){
                    alert(req.response);
                }
            }
        }
}


